<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>let命令</title>
    <script>
      // 用let命令限定作用域
      /* 作用域
       * 局部作用域
       */

      //ES5
      if (true) {
        var i = 1;
      }
      console.log(i); // 输出：1
      //ES6
      if (true) {
        let i = 1;
      }
      console.log(i); // 输出：变量i未找到
      /* 重复定义
       * let禁止重复定义
       */
      //ES5
      var i = 0;
      switch (i) {
        case 0:
          var value = "helo";
          break;
        case 1:
          var value = "world"; //不会报错
          break;
      }
      //ES6
      var i = 0;
      switch (i) {
        case 0:
          let value = "helo";
          break;
        case 1:
          let value = "world"; //重复定义错误
          break;
      }
    </script>
  </head>
  <body></body>
</html>
